import 'package:flutter/material.dart';

class PasswordInput extends StatefulWidget {
  final TextEditingController controller;
  final String? title;
  final double? height;
  const PasswordInput({
    super.key,
    required this.controller,
    this.title = '',
    this.height = 48,
  });

  @override
  State<PasswordInput> createState() => _PasswordInputState();
}

class _PasswordInputState extends State<PasswordInput> {
  bool pwdShow = false;

  OutlineInputBorder _buildCustomBorder() {
    return OutlineInputBorder(
      borderRadius: BorderRadius.circular(10),
      borderSide: BorderSide.none, // 关键设置
    );
  }

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context).colorScheme;  
    return SizedBox(
      height: widget.height,
      child: TextFormField(
        controller: widget.controller,
        style: TextStyle(
          // 控制输入文字样式
          // color: Colors.black, // 输入文字颜色
          fontWeight: FontWeight.w400,
          height: 1, // 调整文字行高（可选）
        ),
        decoration: InputDecoration(
          hintText: '请输入', // 提示文本
          hintStyle: TextStyle(color: Colors.grey[500]), // 提示文本颜色
          prefixIcon: Icon(Icons.lock), // 前缀图标
          prefixIconColor: Colors.grey[500], // 前缀图标颜色
          fillColor: theme.secondary, // 背景色
          filled: true,
          // 移除边框的核心设置
          border: _buildCustomBorder(),
          contentPadding: EdgeInsets.symmetric(
            vertical: widget.height! * 0.3, // 根据高度动态计算垂直内边距
            horizontal: 16,
          ),
          // enabledBorder: InputBorder.none, // 移除激活时的边框
          // focusedBorder: InputBorder.none, // 移除聚焦时的边框
          // errorBorder: InputBorder.none, // 移除错误状态的边框
          // focusedErrorBorder: InputBorder.none, // 移除错误聚焦时的边框
          suffixIcon: IconButton(
            icon: Icon(pwdShow ? Icons.visibility_off : Icons.visibility),
            onPressed: () {
              setState(() {
                pwdShow = !pwdShow;
              });
            },
          ), // 后缀图标
          suffixIconColor: Colors.grey[500], // 后缀图标颜色
        ),
        obscureText: !pwdShow,
      ),
    );
  }
}
